﻿using Engine;
using Game;
using System;

namespace Mekiasm
{
    public class MekInventorySlotWidget : InventorySlotWidget
    {
        public ImageWidget ModeChange = new ImageWidget()
        {
            Size = new Vector2(15)
        };
        
        public MekInventorySlotWidget() : base()
        {

        }
        public void ConfigSlotMode(ComponentMiner miner)
        {
            if (m_inventory is ComponentEnergyMachine machine)
            {
                if (!Children.Contains(ModeChange)) Children.Add(ModeChange);
                var slot = machine.Slots[m_slotIndex];
                if (slot.SlotType.HasFlag(ComponentEnergyMachine.SlotType.Charge_SlotOut)) ModeChange.Texture = ContentManager.Get<Engine.Graphics.Texture2D>("Mekiasm/Gui/Tabs/eject");
                else ModeChange.Texture = ContentManager.Get<Engine.Graphics.Texture2D>("Mekiasm/Gui/Tabs/input");
                ModeChange.Clicked = () => {

                    slot.SetSlotTypeFlag(ComponentEnergyMachine.SlotType.Charge_SlotOut, !slot.SlotType.HasFlag(ComponentEnergyMachine.SlotType.Charge_SlotOut));

                    if (slot.SlotType.HasFlag(ComponentEnergyMachine.SlotType.Charge_SlotOut))
                    {
                        ModeChange.Texture = ContentManager.Get<Engine.Graphics.Texture2D>("Mekiasm/Gui/Tabs/eject");
                        miner?.ComponentPlayer.ComponentGui.DisplaySmallMessage("注入模式", Color.White, false, true);
                    }
                    else
                    {
                        ModeChange.Texture = ContentManager.Get<Engine.Graphics.Texture2D>("Mekiasm/Gui/Tabs/input");
                        miner?.ComponentPlayer.ComponentGui.DisplaySmallMessage("反灌模式", Color.White, false, true);
                    }
                };
            }
        }

        public override void Update()
        {
            base.Update();
        }

    }
}
